package com.hxx.front;

import com.hxx.controller.UserController;
import com.hxx.domain.TUser;

import java.util.List;
import java.util.Scanner;

public class UserFront {

    public static void main(String[] args) {
        UserController userController = new UserController();
        Scanner scanner = new Scanner(System.in);
        boolean flag = true;
        while (flag){
            System.out.println("请输入您的选择：1.添加用户 2.获取用户 3.获取所有用户 4.更新用户 5.删除用户 6.退出");
            int choice = scanner.nextInt();
            switch (choice){
                case 1:
                    System.out.println("请输入用户名、性别、年龄");
                    String username = scanner.next();
                    String sex = scanner.next();
                    int age = scanner.nextInt();
                    TUser tUser = new TUser(null,username,sex,age);
                    userController.addUser(tUser);
                    System.out.println("添加成功");
                    break;
                case 2:
                    System.out.println("请输入用户ID");
                    int id = scanner.nextInt();
                    TUser user = userController.getUser(id);
                    System.out.println(user);
                    break;
                case 3:
                    List<TUser> allUser = userController.getAllUser();
                    System.out.println(allUser);
                    break;
                case 4:
                    System.out.println("请输入用户ID、用户名、性别、年龄");
                    id = scanner.nextInt();
                    username = scanner.next();
                    sex = scanner.next();
                    age = scanner.nextInt();
                    tUser = new TUser(id,username,sex,age);
                    userController.updateUser(tUser);
                    System.out.println("更新成功");
                    break;
                case 5:
                    System.out.println("请输入用户ID");
                    id = scanner.nextInt();
                    userController.deleteUser(id);
                    System.out.println("删除成功");
                    break;
                case 6:
                    flag = false;
                    break;
                default:
                    System.out.println("输入错误，请重新输入");
                    break;
            }
        }
    }
}

































